#!/usr/bin/env bash

curdir="$(cd "$(dirname $(realpath ${BASH_SOURCE[0]}))"; pwd)"
export SHRC_DIR=$curdir

OS=$(uname -s)
case $OS in
    (Linux)
        sudo apt install -y zsh
        ;;
    (Darwin)
        # mac 自带 zsh 版本不新, 同时 bash 3.2 版本太低了, 一并升级
        brew install bash zsh
        ;;
    (*)
        echo "Unknown \$(uname -s): $OS"
        exit 1
        ;;
esac

# 安装 zsh

# 安装 oh-my-zsh
#

if [[ -z $ZSH ]]; then
    mkdir -p $HOME/.config
    ZSH=$HOME/.config/oh-my-zsh
    unset ZSH_CUSTOM
fi
echo "ZSH=$ZSH"

export ZSH
# curl -L https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash
git clone --depth=1 --single-branch https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git $ZSH
# 一步到位, 不需要执行脚本了
# pushd "$ZSH/tools"
# REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh install.sh --unattended --keep-zshrc

# 安装插件
${SHRC_DIR}/init-plugins.sh

# 启用 zsh
${SHRC_DIR}/enable.sh
